<%--
  Created by IntelliJ IDEA.
  User: 李俊
  Date: 2022/9/16
  Time: 11:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<div align="center">
    <h1>添加个人简历信息</h1>
    <form action="ResumeInsertServlet">
        <table border="1" style="background-color: slategrey">
            <tr>
                <td>姓名</td>
                <td><input type="text" name="userName" id="userName">
                    <span id="username1"></span></td>
            </tr>
            <tr>
                <td>性别</td>
                <td><input type="radio" name="sex" checked value="男"> 男 <input type="radio" value="女" name="sex">
                </td>
            </tr>
            <tr>
                <td>籍贯地址</td>
                <td><input type="text" name="address" id="address">
                    <span id="address1"></span></td>
            </tr>
            <tr>
                <td>出生日期</td>
                <td><input type="text" name="birth" id="birth">
                    <span id="birth1">格式：yyyy-MM-dd出生日期不能为空</span>
                </td>
            </tr>
            <tr>
                <td>
                    联系电话
                </td>
                <td>
                    <input type="text" name="telephone" id="telephone">
                    <span id="telephone1"></span>
                </td>
            </tr>
            <tr>
                <td>毕业学校</td>
                <td>
                    <input type="text" name="school" id="school">
                    <span id="school1"></span>
                </td>
            </tr>
            <tr>
                <td>简历状态</td>
                <td><input type="radio" value="1" name="status" checked> 公开 <input type="radio" name="status"
                                                                                     value="0"> 保密
                </td>
            </tr>
            <tr>
                <td>操作</td>
                <td><input type="submit" value="新增"> <input type="button" value="返回" onclick="fanhui()"></td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>
<script src="js/jquery-1.8.3.min.js"></script>
<script>
    function fanhui() {
        location.href = "ResumeViewAll.jsp"
    }

    $("form").submit(function () {
        let deu = false;
        $("#username1").html("");
        $("#address1").html("");
        $("#birth1i").html("格式：yyyy-MM-dd出生日期不能为空");
        $("#telephone1").html("");
        $("#school1").html("");
        let isTime = /^\d\d\d\d[-]\d\d[-]\d\d$/;
        if ($("#userName").val().trim() == "") {
            $("#username1").html("姓名不能为空");
            return false
        }
        if ($("#address").val().trim() == "") {
            $("#address1").html("籍贯地址不能为空");
            return false
        }
        if ($("#birth").val().trim() == "") {
            $("#birth1i").html("格式：yyyy-MM-dd出生日期不能为空  出生日期不能为空");
            return false
        }
        if ($("#telephone").val().trim() == "") {
            $("#telephone1").html("联系电话不能为空");
            return false
        }
        if ($("#school").val().trim() == "") {
            $("#school1").html("毕业学校不能为空");
            return false
        }
        if (!isTime.test($("#birth").val())) {
            $("#birth1i").html("格式：yyyy-MM-dd出生日期不能为空  时间格式不正确");
            return false
        }
        $.ajaxSettings.async = false;
        $.post("ResumeViewServlet", "phone=" + document.getElementById("telephone").value, function (data) {
            if (data == "true") {
                $("#telephone1").html("电话号码不可用")
                deu = true;
            } else {
                $("#telephone1").html("电话号码可用")
                deu = false;
            }
        }, "text");
        if (deu) {
            return false
        } else {
            return true
        }
    });
</script>
